package op;

import java.awt.image.*;
import java.util.Random;

public class EffectOp {
	private static double[][] pencilModel = new double[][]{{0, -1, 0}, {-1, 4, -1}, {0, -1, 0}};
	
	private static int PERCILBRIGHT = -150;
	private static double PERCILCONTRAST = 2;
	
	private static int OILRADIUM = 7;
	
	public static BufferedImage pencilOp(BufferedImage image){
		image = ImageOp.guassOp(image);
		
		double[][] oldData = ShareFunc.readoutD(image);	
		double[][] newData = ShareFunc.turnMul(oldData, pencilModel);
		
		BufferedImage newImage = ImageOp.reverseOp(ShareFunc.writein(newData, image.getType()));
		newImage = ImageOp.linearOp(newImage, PERCILBRIGHT, PERCILCONTRAST);
		
		return newImage;
	}
	
	public static BufferedImage oilOp(BufferedImage image){
		BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight()
				, image.getType());
		
		Random random = new Random();
		int height = image.getHeight();
		int width = image.getWidth();
		
		for(int i=0; i<height; i++)
			for(int j=0; j<width; j++){
				int newi = i+random.nextInt(OILRADIUM)-OILRADIUM/2;
				if(newi < 0) newi = 0;
				if(newi >= height) newi = height-1;
				int newj = j+random.nextInt(OILRADIUM)-OILRADIUM/2;
				if(newj < 0) newj = 0;
				if(newj >= width) newj = width-1;
				newImage.setRGB(j, i, image.getRGB(newj, newi));
			}
		
		return newImage;
	}
}
